package com.csc.banking.dao;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Repository;
@Repository
public class UserAccountDao implements UserDetailsService{
	//@PersistenceContext private EntityManager em;
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		UserDetails user = new User(username, "password", true, true, true, true,getAuthorities(0));
		return user;
	}
	public Collection<GrantedAuthority> getAuthorities(Integer access) {
	    List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>(2);

	    if (access.compareTo(access) == 0) {
	        authList.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
	    }
	    else{
	        authList.add(new SimpleGrantedAuthority("ROLE_USER"));
	    }
	    return authList;
	}

}
